package com.dayuanit.dy17.oauth.autoconfig.wxloginspringbootstarter.autconfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({WxLoginProperties.class})
public class WxLoginAutoConfiguration {

    @Autowired
    private WxLoginProperties wxLoginProperties;

    @Bean
    @ConditionalOnProperty(prefix = "atm.wx", name="app-id")
    public WxLoginHandler wxLoginHandler() {
        WxLoginHandler handler = new WxLoginHandler();
        handler.setAppId(wxLoginProperties.getAppId());
        handler.setRedirectUrl(wxLoginProperties.getRedirectUrl());
        handler.setSecret(wxLoginProperties.getSecret());
        handler.setWxAccessTokenUrl(wxLoginProperties.getWxAccessTokenUrl());
        handler.setWxLoginUrl(wxLoginProperties.getWxLoginUrl());
        handler.setWxUserInfoUrl(wxLoginProperties.getWxUserInfoUrl());
        return handler;
    }

}
